#include "../base/MGraph-ToSort.c"
#include "../base/MGraph-input.c"

int main() {
    int n, m;
    scanf("%d %d", &n, &m);

    // 建立初始为最大权重的有向图
    MGraph* g = createGraph(DirectedGraph, MaxWeight, n);
    // 读取 m 条边
    readEdgeV0WithWeight(g, m);
    printGraph(g);

    int* topOrder = (int*)calloc(n, sizeof(int));
    int* earliest = (int*)calloc(n, sizeof(int));
    if (topSort(g, topOrder, earliest)) {
        printf("%d\n", findMax(earliest, n));
    } else {
        printf("Impossible\n");
    }

    free(topOrder);
    free(earliest);
    freeGraph(g);
    return 0;
}
